package com.demo.controller;


import com.demo.api.ResponseResult;
import com.demo.pojo.Category;
import com.demo.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.*;

// 告诉spring mvc这是一个控制器类
@Controller
@RequestMapping("")
@Validated
public class CategoryController {
	@Autowired
	CategoryService categoryService;

	@ApiOperation(value = "接口测试")
	@RequestMapping(value = "/demo",method = RequestMethod.POST)
	@ResponseBody
	public ResponseResult demo(@RequestBody @Valid Category category){
		System.out.println(category);
		ResponseResult responseResult=new ResponseResult();
		responseResult.setCode(HttpStatus.OK.value());
		responseResult.setMsg(HttpStatus.OK.getReasonPhrase());
		return responseResult;
	}

	@ApiOperation(value = "data接口测试")
	@RequestMapping(value = "/datademo",method = RequestMethod.POST)
	@ResponseBody
	public ResponseResult<Category> datademo(){


		ResponseResult<Category> responseResult=new ResponseResult<Category>();
		responseResult.setCode(HttpStatus.OK.value());
		responseResult.setMsg(HttpStatus.OK.getReasonPhrase());
		Category category=new Category();
		category.setId(12);
		category.setName("zzz");
		responseResult.setData(category);
		return responseResult;
	}
	@ApiOperation(value = "data List接口测试")
	@RequestMapping(value = "/listdatademo",method = RequestMethod.POST)
	@ResponseBody
	public ResponseResult<List<Category>>listdatademo(){
		ResponseResult<List<Category>> responseResult=new ResponseResult<List<Category>>();
		responseResult.setCode(HttpStatus.OK.value());
		responseResult.setMsg(HttpStatus.OK.getReasonPhrase());
		Category category=new Category();
		category.setId(12);
		category.setName("zzz");
		List<Category> list=new ArrayList<Category>();
		list.add(category);
		list.add(category);
		responseResult.setData(list);
		return responseResult;
	}

}
